#ifndef __DEBUG_H
#define __DEBUG_H

#include "base.h"

#define DEBUG_LEVEL_NONE 0
#define DEBUG_LEVEL_YELL 1
#define DEBUG_LEVEL_NOTICE 2
#define DEBUG_LEVEL_CASUAL 3
#define DEBUG_LEVEL_TRACE 4
#define DEBUG_LEVEL 0
#ifndef DEBUG_LEVEL
#define DEBUG_LEVEL DEBUG_LEVEL_TRACE
#endif

#define eprintf(format, args...) (fprintf(stderr, format, ##args))

#ifdef DEBUG_LEVEL

#define DEBUG_PRINT(level, format, args...) \
	do { \
		if ((level) <= DEBUG_LEVEL) \
		{ \
			eprintf("*DEBUG MESSAGE: %s: %s:%d: " format "\n", __FILE__, __FUNCTION__, __LINE__, ##args) ; \
		} \
	} while (0)
#else
#define DEBUG_PRINT(level, format, args...) do {} while (0)
#endif /* DEBUG_LEVEL */

#define DEBUG_YELL(format, args...)		DEBUG_PRINT(DEBUG_LEVEL_YELL, format, ##args)
#define DEBUG_NOTICE(format, args...)	DEBUG_PRINT(DEBUG_LEVEL_NOTICE, format, ##args)
#define DEBUG_CASUAL(format, args...)	DEBUG_PRINT(DEBUG_LEVEL_CASUAL, format, ##args)
#define DEBUG_TRACE(format, args...)	DEBUG_PRINT(DEBUG_LEVEL_TRACE, format, ##args)

#define DEBUG_ENTER(format, args...)	DEBUG_TRACE("entering -- " format, ##args)
#define DEBUG_EXIT(format, args...)		DEBUG_TRACE("exiting -- " format, ##args)

#define DEBUG_ASSERT(condition) \
	do \
	{ \
		if (!(condition)) \
		{ \
			DEBUG_YELL("condition << %s >> evaluates to FALSE\n", #condition) ; \
			exit(-1) ; \
		} \
	} while (0)

#define DEBUG (defined(DEBUG_LEVEL) && (DEBUG_LEVEL > DEBUG_LEVEL_NONE))

#endif /* __DEBUG_H */

